package leetcode.editor.cn;

import org.junit.Assert;

public class P367ValidPerfectSquare {
    public static void main(String[] args) {
        Solution solution = new P367ValidPerfectSquare().new Solution();
        Assert.assertTrue(solution.isPerfectSquare(2147395600));

    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean isPerfectSquare(int num) {
            int low = 0, high = num;
            while (low <= high) {
                int mid = (high - low) / 2 + low;
                if (mid == 0) {
                    low = mid + 1;
                    continue;
                }
                int i1 = num / mid;
                int i2 = num % mid;
                if (i1 == mid && i2 == 0) {
                    return true;
                } else if (i1 < mid) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return false;
        }

    }
//leetcode submit region end(Prohibit modification and deletion)

}